<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" id="i1">
<input type="button" value="平方" onclick="f()">
<div>
    结果:<span></span>
</div>
<script>
    function f() {
        let i = document.querySelector("#i1");
        let s = document.querySelector("span");
        //判断输入的内容是否是数值
        if(isNaN(i.value)){
            s.innerText = "输入错误！";
            return;//结束方法
        }
        //当字符串进行-*/运算时会自动将字符串转成数值进行运算
        // s.innerText = i.value*i.value;
        //在进行加法运算时 需要先将字符串转成数值 再运算
        // s.innerText = parseFloat(i.value)+parseFloat(i.value);
        s.innerText = i.value*1+i.value*1;
    }
</script>
</body>
</html>